# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Adrián Pérez de Castro <aperez@igalia.com>

pkgname=lowdown
pkgver=1.0.2
pkgrel=2
pkgdesc='A simple Markdown translator'
arch=('loong64' 'x86_64')
url='https://kristaps.bsd.lv/lowdown'
license=('ISC')
depends=('glibc' 'libmd')
makedepends=('git')
provides=('liblowdown.so')
_commit='45c3ffad5fe3b51360afe6e566ec54edcb13718f'
source=("$pkgname::git+https://github.com/kristapsdz/lowdown.git#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed -e 's/^VERSION_//' -e 's/_/./g'
}

build () {
  cd "$pkgname"

	./configure \
    PREFIX=/usr \
    MANDIR=/usr/share/man

  # ensure LDFLAGS is passed correctly
  sed -i "s/^LDFLAGS.*/LDFLAGS = $LDFLAGS/" Makefile.configure

	make
}

check () {
	make -C "$pkgname" regress
}

package () {
  cd "$pkgname"

  # package
	make DESTDIR="$pkgdir" \
    install \
    install_lib_common \
    install_shared

  # symlink unversioned to versioned shared library
  local LIBVER=$(grep "^LIBVER" Makefile | sed "s/.*= //")
  ln -sf "/usr/lib/liblowdown.so.$LIBVER" "$pkgdir/usr/lib/liblowdown.so"

  # license
	install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE.md
}
